package org.weed.remote.network.server;

import java.io.IOException;
import java.net.InetAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class HttpNioServer extends NioServer {
	private final int NUMBER_OF_THREADS = 5;
	private ExecutorService executor;

	public HttpNioServer(InetAddress hostAddress, int port) throws IOException {
		super(hostAddress, port);
		executor = Executors.newFixedThreadPool(NUMBER_OF_THREADS);
	}
	
	@Override
	public void doRead(SelectionKey key) throws IOException {
		SocketChannel socketChannel = (SocketChannel) key.channel();
		buffer.clear();
		int bytesRead;
		try {
			bytesRead = socketChannel.read(buffer);
			System.out.println(buffer);
		} catch (Exception e) {
			key.cancel();
			socketChannel.close();
			return;
		}
	}
	
	@Override
	public void doWrite(SelectionKey key) throws IOException {
		SocketChannel socketChannel = (SocketChannel) key.channel();
	}
	
	public static void main(String[] args) {
		try {
			HttpNioServer server = new HttpNioServer(null, 80);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		
	}

}
